﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <link href="/style/rightdirectory.css" rel="stylesheet" />
    <script src="/script/config.js"></script>
</head>

<body>
    <h5>短信操作</h5>
    <div class="form-body">
        <div class="form-horizontal  hide" id="form">
            
        </div>
    </div>
</body>
</html>
<script type="text/html" id="tp-form">
    <div class="form-group">
        <label class="col-sm-2">微信APPId</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" data-form="AppId" placeholder="微信APPId" value="{{AppId}}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2">微信AppSecret</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" data-form="AppSecret" placeholder="微信AppSecret" value="{{AppSecret}}">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="btn-submit" class="btn btn-primary">保存</button>
            <button type="button" class="btn" onclick="window.history.go(-1)">退出</button>
        </div>
    </div>
</script>
<link href="/script/valid/css/tr.css" rel="stylesheet" /><!--判断如：PlatformName格式-->
<script src="/script/valid/form-valid.js?v=2018"></script>
<script>
    $(function () {
        var id = QueryPageUrlString("v");//判断是否是编辑进来的
        var formValidEvent;
        var formValidInit = function () {
            var formValidData = [
                {
                    key: "AppId",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },{
                    key: "AppSecret",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
               
            ];
            formValidEvent = $(".form-body").formValid(formValidData);
        }    
        
        if (id > 0) { //存在值的情况
            $.http.json("wechatconfig/find", {   //查询
                Id: id
            }, {
                    pass: function (data) {
                        
                    $("#form").templateRender({ el: "tp-form", data: data });
                    formValidInit();
                },
                error: function (d) {
                    console.log(d);
                }
            })
        } else {
            $("#form").templateRender({ el: "tp-form", data: inintData });
            formValidInit();
        }
        $("#form").on("click", "#btn-submit", function () { //保存按钮有添加和编辑
            if (!formValidEvent.check()) { return; }
            var apiUrl = "wechatconfig/upd";
            $("#form").ajaxFormSubmit(apiUrl, {
                pass: function (d) {
                    
                    $.msgSucceed(d.Errmsg);

                }, error: function (d) {
                    console.log(d)
                    $.msgFall(d.Errmsg);
                }
            }, { addData: { Id: id } })
            return
        })
    })
</script>
